package com.bittech.facerecognition.model;

import com.google.gson.Gson;
import com.google.gson.GsonBuilder;

/**
 * Author: secondriver
 * Created: 2019/5/28
 */
public class Response<T> {
    
    private static final Gson GSON = new GsonBuilder()
            .serializeSpecialFloatingPointValues()
            .create();
    
    //成功标识
    private static final int OK = 200;
    //失败标识
    private static final int FAILED = 600;
    
    private final int status;
    private final String message;
    private final T data;
    
    private Response(int status, String message, T data) {
        this.status = status;
        this.message = message;
        this.data = data;
    }
    
    public static <T> Response<T> ofOk(T data) {
        return new Response<>(OK, "", data);
    }
    
    public static <T> Response<T> ofFailed(T data, String message) {
        return new Response<>(FAILED, message, data);
    }
    
    public int getStatus() {
        return status;
    }
    
    public String getMessage() {
        return message;
    }
    
    public T getData() {
        return data;
    }
    
    @Override
    public String toString() {
        return GSON.toJson(this);
    }
}